#ifndef __ZBOX_ZBUSCLI_H__
#define __ZBOX_ZBUSCLI_H__

#include "zmsg.h"

#ifdef __cplusplus
extern "C" {
#endif
//  This is the version of MDP/Client we implement
#define MDPC_CLIENT         "MDPC01"

//  This is the version of MDP/Worker we implement
#define MDPW_WORKER         "MDPW01"


//  MDP/Server commands, as strings
#define MDPW_READY          "\001"
#define MDPW_REQUEST        "\002"
#define MDPW_REPLY          "\003"
#define MDPW_HEARTBEAT      "\004"
#define MDPW_DISCONNECT     "\005"
#define MDPW_SYNC		    "\006"

#define MODE_REQREP			"1"
#define MODE_MQ				"2"
#define MODE_PUBSUB			"3"

#define HEARTBEAT_LIVENESS		3

#define ZBUS_EXPORT ZBOX_EXPORT 

typedef struct _zbuscli_t zbuscli_t;
typedef struct _zbuswrk_t zbuswrk_t;
typedef struct _zbuscli_cfg_t zbuscli_cfg_t;
typedef struct _zbuswrk_cfg_t zbuswrk_cfg_t;
typedef zmsg_t* (*msg_cb)(zmsg_t*);
typedef void	(*worker_cb)(zbuswrk_t*);


/////////////////////////////////////////////client/////////////////////////////////////////
ZBUS_EXPORT zbuscli_cfg_t*
	zbuscli_cfg_new();
ZBUS_EXPORT void
	zbuscli_cfg_destroy(zbuscli_cfg_t** self_p);
ZBUS_EXPORT void
	zbuscli_cfg_set_ctx(zbuscli_cfg_t* self, void* ctx);
ZBUS_EXPORT void
	zbuscli_cfg_set_broker(zbuscli_cfg_t* self, char* host, int port);
ZBUS_EXPORT void
	zbuscli_cfg_set_verbose(zbuscli_cfg_t* self, int verbose);
ZBUS_EXPORT void
	zbuscli_cfg_set_timeout(zbuscli_cfg_t* self, int timeout);
ZBUS_EXPORT void
	zbuscli_cfg_set_retries(zbuscli_cfg_t* self, int retries);
ZBUS_EXPORT void
	zbuscli_cfg_set_iothreads(zbuscli_cfg_t* self, int iothreads);


ZBUS_EXPORT zbuscli_t*
	zbuscli_new(zbuscli_cfg_t* cfg);
ZBUS_EXPORT void
	zbuscli_destroy(zbuscli_t** self_p);
ZBUS_EXPORT zmsg_t*
	zbuscli_request(zbuscli_t* self, char* service, char* token, zmsg_t* request);


//////////////////////////////////////////////worker/////////////////////////////////////////
ZBUS_EXPORT zbuswrk_cfg_t*
	zbuswrk_cfg_new();
ZBUS_EXPORT zbuswrk_cfg_t*
	zbuswrk_cfg_dup(zbuswrk_cfg_t* from);
ZBUS_EXPORT void
	zbuswrk_cfg_destroy(zbuswrk_cfg_t** self_p);
ZBUS_EXPORT void
	zbuswrk_cfg_set_ctx(zbuswrk_cfg_t* self, void* ctx);
ZBUS_EXPORT void
	zbuswrk_cfg_set_verbose(zbuswrk_cfg_t* self, int verbose);
ZBUS_EXPORT void
	zbuswrk_cfg_set_heartbeat(zbuswrk_cfg_t* self, int heartbeat);
ZBUS_EXPORT void
	zbuswrk_cfg_set_reconnect(zbuswrk_cfg_t* self, int reconenct);
ZBUS_EXPORT void
	zbuswrk_cfg_set_timeout(zbuswrk_cfg_t* self, int timeout);
ZBUS_EXPORT void
	zbuswrk_cfg_set_service(zbuswrk_cfg_t* self, char* servcie);
ZBUS_EXPORT void
	zbuswrk_cfg_set_regtoken(zbuswrk_cfg_t* self, char* regtoken);
ZBUS_EXPORT void
	zbuswrk_cfg_set_acctoken(zbuswrk_cfg_t* self, char* regtoken);
ZBUS_EXPORT void
	zbuswrk_cfg_set_mode(zbuswrk_cfg_t* self, char* mode);
ZBUS_EXPORT void
	zbuswrk_cfg_add_broker(zbuswrk_cfg_t* self, char* host, int port);
ZBUS_EXPORT void
	zbuswrk_cfg_set_broker(zbuswrk_cfg_t* self, char* broker);
ZBUS_EXPORT void
	zbuswrk_cfg_set_broker2(zbuswrk_cfg_t* self, char* host, int port); 


ZBUS_EXPORT zbuswrk_t*
	zbuswrk_new(zbuswrk_cfg_t* cfg);
ZBUS_EXPORT void
	zbuswrk_destroy(zbuswrk_t** self_p); 

ZBUS_EXPORT zmsg_t*
	zbuswrk_recv(zbuswrk_t* self, zmsg_t* reply);
ZBUS_EXPORT void
	zbuswrk_pool_msg_cb(zbuswrk_cfg_t* cfg, int wrk_threads, msg_cb cb);
ZBUS_EXPORT void
	zbuswrk_pool_worker_cb(zbuswrk_cfg_t* cfg, int wrk_threads, worker_cb cb);

#ifdef __cplusplus
}
#endif

#endif /* __ZBUSCLI_H__ */
